import $ from 'jquery';
import { sleep } from '../../utils/other';

const el = $(".app-ready");
const img = $(".app-ready img");
const btn = $(".app-ready button");
const newyear = $(".app-newyear");
const newyears = $(".app-newyear>p");
var isStarting = false;
var startEvent = null;

function onStart(listener) {
    startEvent = listener;
}

function init() {
    el.removeClass("hide");
    setTimeout(() => {
        img.removeClass("hide");
        setTimeout(() => {
            btn.removeClass("hide");
            btn.on("click", start);
            $(window).on("keydown", start)
        }, 400);
    }, 800);
};

function start() {
    if (isStarting) return;
    isStarting = true;
    startEvent();
    el.addClass("hide");
    setTimeout(() => {
        el.addClass("none");
    }, 1000);
};

async function showNewYear() {
    newyear.removeClass("none");
    await sleep(100)
    newyear.removeClass("hide");
    await sleep(500)
    for (let v of newyears) {
        $(v).removeClass("hide");
        await sleep(250)
    }
}

async function hideNewYear() {
    newyear.addClass("hide");
    await sleep(1000)
    newyear.addClass("none");
    for (let v of newyears) {
        $(v).addClass("hide");
    }

}

export { init, start, onStart, showNewYear, hideNewYear };